using System.Windows;
using System.Windows.Controls;
using Chaotic.DataBase.DBAccessLibrary.Model;

namespace Chaotic.Module.DBTool.TemplateSelectors;

public class ContextMenuDataTemplateSelector : DataTemplateSelector
{
	public override DataTemplate SelectTemplate(object item, DependencyObject container)
	{
		FrameworkElement frameworkElement = container as FrameworkElement;
		DataTemplate result = null;
		if (frameworkElement == null)
		{
			return null;
		}
		if (item is ServerEntity)
		{
			result = frameworkElement.FindResource("ServerTemplate") as HierarchicalDataTemplate;
		}
		else if (item is DBEntity)
		{
			result = frameworkElement.FindResource("DBTemplate") as HierarchicalDataTemplate;
		}
		else if (item is TableInfoEntity)
		{
			result = frameworkElement.FindResource("TableInfoTemplate") as HierarchicalDataTemplate;
		}
		else if (item is IndexDescriptionEntity)
		{
			result = frameworkElement.FindResource("IndexDescriptionTemplate") as HierarchicalDataTemplate;
		}
		else if (item is DescriptionEntity)
		{
			result = frameworkElement.FindResource("DescriptionTemplate") as HierarchicalDataTemplate;
		}
		else if (item is TableEntity)
		{
			result = frameworkElement.FindResource("TableTemplate") as HierarchicalDataTemplate;
		}
		else if (item is ProcParamEntity)
		{
			result = frameworkElement.FindResource("ProcParamTemplate") as HierarchicalDataTemplate;
		}
		else if (item is FieldEntity)
		{
			result = frameworkElement.FindResource("FieldTemplate") as HierarchicalDataTemplate;
		}
		else if (item is ProcEntity)
		{
			result = frameworkElement.FindResource("ProcTemplate") as HierarchicalDataTemplate;
		}
		else if (item is ViewEntity)
		{
			result = frameworkElement.FindResource("ViewTemplate") as HierarchicalDataTemplate;
		}
		else if (item is RelationshipEntity)
		{
			result = frameworkElement.FindResource("ForeignTemplate") as HierarchicalDataTemplate;
		}
		else if (item is IndexEntity)
		{
			result = frameworkElement.FindResource("IndexTemplate") as HierarchicalDataTemplate;
		}
		return result;
	}
}
